package com.itgaoshu.hospitalproject.controller;

import com.itgaoshu.hospitalproject.bean.*;
import com.itgaoshu.hospitalproject.service.OutpatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("cao")
public class OutpatientController {
    @Autowired
    private OutpatientService outpatientService;
    //@ResponseBody
    //查询所有挂号病人
    @RequestMapping("index")
    public Object selectAllReport(Model model, @RequestParam(defaultValue = "1") int pageNum){
        //PageHelper.startPage(pageNum,5);
        List<ReportVo> reportVos=outpatientService.selectAllReport();
       // PageInfo pageInfo=new PageInfo(reportVos);
        /*Map<String, Object> tableData = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）T
        tableData.put("data", pageInfo.getList());*/

        model.addAttribute("reportVo",reportVos);
        return "cao/report";
    }

    //@ResponseBody
    //添加
    @RequestMapping("addre")
    public Object addReport(CReport reportVo){
        /*ReportVo reportVo=new ReportVo();
        reportVo.setReportName("刘备");
        reportVo.setSex("男");
        reportVo.setAge(18);
        reportVo.setPhone("17912345678");
        reportVo.setCarid("123456789012345678");
        reportVo.setDepartment("7");
        reportVo.setDredisteredid(5);
        reportVo.setDdoctorid(13);
        reportVo.setPrice(20);*/

        int reslut=outpatientService.addReport(reportVo);
        if(reslut>0){
            return "redirect:index";
        }else {
            return "添加失败";
        }
    }
    @ResponseBody
    @RequestMapping("seldep")
    public Object selectAllCDe(){
        List<CDepartments> seldep=outpatientService.selectAllCDe();
        return seldep;
    }

    @RequestMapping("selreg")
    @ResponseBody
    public Object selectAllReg(){
        List<CRegisteredtype> selreg= outpatientService.selectAllReg();
        return selreg;
    }
    @RequestMapping("seldoctor")
    @ResponseBody
    public Object selectAllDoc(){
        List<Doctor> doctors =outpatientService.selectAllDoc();
        return doctors;
    }

    @RequestMapping("seltymo")
    @ResponseBody
    public Object seltymo(int registeredId){
        int seltymo=outpatientService.seltymo(registeredId);
        return seltymo;
    }

    @RequestMapping("phone")
    @ResponseBody
    public Object phone(String carid,String phone){
        int carid1=outpatientService.selectCcarid(carid);
        int phone1=outpatientService.selectPhone(phone);
        if(carid1>=1){
            return 2;
        }else if(phone1>=1){
            return 1;
        }else{
            return 3;
        }
    }

    @RequestMapping("selch")
    @ResponseBody
    public Object  selectsumrep(int reportId){
        Double selch= outpatientService.selectsumrep(reportId);
        return selch;
    }

    @RequestMapping("seljiao")
    @ResponseBody()
    public Object seljiao(Integer reid){
        int seljiao = outpatientService.selectxiangmu(reid);
        return seljiao;
    }
    //删除
    @RequestMapping("delre")
    public Object deleteReport(int id){
        int result=outpatientService.deleteReport(id);
        if (result>0){
            return "redirect:index";
        }else {
            return "删除失败";
        }
    }

    //转院
    @RequestMapping("zhuanyuan")
    public Object updateReport(String zhuan, Integer id){
        int result=outpatientService.updateReport(zhuan,id);
        if (result>0){
            return "redirect:index";
        }else {
            return "转院失败";
        }
    }

    //查看该用户是否有缴费未做的项目
    @RequestMapping("selwei")
    @ResponseBody
    public Object selwei(Integer reid){
        //查询该用户有几个做过的项目
        Integer selyi = outpatientService.selectyi(reid);
        //查询该用户有几个缴费的项目
        Integer selgong = outpatientService.selectgong(reid);
        if(selyi==selgong){
            return 1;
        }else {
            return 0;
        }
    }

}
